import requests

from engine.youdao.AuthV3Util import addAuthParams


def t_yuodao(word,appid,appkey,kind="en"):
    try:
        data = {'q': word, 'from': 'zh-CHS', 'to': kind, 'vocabId': ""}
        addAuthParams(appid, appkey, data)
        header = {'Content-Type': 'application/x-www-form-urlencoded'}
        res = doCall('https://openapi.youdao.com/api', header, data, 'post')
        r= res.json()["translation"][0]
        return r
    except:
        "1error"

def doCall(url, header, params, method):
    if 'get' == method:
        return requests.get(url, params)
    elif 'post' == method:
        return requests.post(url, params, header)



